#!/usr/bin/env python
# coding=utf-8

from spiders.fetcher_track import TaskGenerator_ChkTrackingInfo

def test(item,conn,log):
    f = TrackFetcher(
        item=item,
        conn=conn,
        proxy={"http":"http://127.0.0.1:8087"},
        log=log
    )
    for i in range(3):
        re = f.Fetch()
        time.sleep(1)
        log.info(re)

def test1():
    import vavava.workqueue
    wq = vavava.workqueue.WorkQueue()
    wq.wq_start()
    wq.QueueWork(
        TaskGenerator_ChkTrackingInfo.get_instance(
            "3,,,,log,nname"
        )
    )
    wq.wq_stop()

if __name__ == '__main__':
    import MySQLdb,vavava.util,time,os
    from DBUtils import PooledDB
    log = vavava.util.initlog("./log/"+ os.path.split(__file__)[1]+".log")

    item = r'UQV0001123'
    dbpool = PooledDB.PooledDB(
        MySQLdb,10,20,10,20,False,
        host='localhost',user='root',
        passwd='root',db='tracking',charset='utf8' )
    conn = dbpool.connection()
    item = r'UQV0001123'

    try:
        test1()
        #test(item,conn,log)
    except(KeyboardInterrupt):
        log.error('main thread(%f): User canceled by Ctrl-c'%time.clock())
    finally:
        log.info('main thread(%f):stop'%time.clock())
        if conn:
            conn.close()
        if dbpool:
            dbpool.close()
        log.info('main thread(%f):stopped'%time.clock())


